<?php

	echo '<pre>';

	if(function_exists('zip_open')) 
	{

		$handle	= fopen('http://localhost/movies.zip', 'r');
		$write	= fopen('movies.zip', 'w');
		
		while(!@feof($handle)) fwrite($write, fgets($handle, 1024));
		
		fclose($handle);
		fclose($write);
	
		// Extract zip file
		
	
		unzip('/server/htdocs/installer_test/movies.zip', '');
		
	
	} 
	else 
	{
	
		echo 'you must have the zip library installed to use this file';
	
	}

	function unzip($file, $des_path) 
	{
		
		$zip	= zip_open($file);
		
		if(!is_dir($des_path)) mkdir($des_path);
		
		if($zip) 
		{
		
			while($zip_entry = zip_read($zip)) 
			{
				
				if (zip_entry_open($zip, $zip_entry, "r")) 
				{
					
					$zip_name	= zip_entry_name($zip_entry);
					$zip_size	= zip_entry_filesize($zip_entry);
					
					$buf		= zip_entry_read($zip_entry, $zip_size);
					$host_dir	= dirname($zip_name);
					
					$path = $des_path . $zip_name;
					
					$abs_path	= '/server/htdocs/installer_test/';
					
					if($host_dir != '.') 
					{
						
						foreach(explode('/', $host_dir) as $v) 
						{
							
							$abs_path = $abs_path . $v .'/';
						
						}
						
						if(is_file($abs_path)) unlink($abs_path);
						
						if(!is_dir($abs_path)) mkdir($abs_path);
						
					}

					write_file($path, $buf);
					
					zip_entry_close($zip_entry);
					
				}
			
			}
			
			zip_close($zip);
			
		}
		
	}

	function write_file($path, $data) 
	{
		
		$f = fopen($path, 'w');
		
		if($f) 
		{
			
			$write = fwrite($f, $data);
			
			fclose($f);
			
			if($f) return true;
			
		}
		
		echo $path ." failed\n";
		
		return false;
		
	}

?>